package com.marion.jpa.repo;

import com.marion.jpa.entity.TUserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

/**
 * @author Marion
 * @date 2022/3/2 14:38
 */
public interface UserRepo extends JpaRepository<TUserEntity, Long>,
        PagingAndSortingRepository<TUserEntity, Long>,
        JpaSpecificationExecutor<TUserEntity> {

    @Override
    Optional<TUserEntity> findById(Long id);

    @Query(value = "select * from t_user where (:name is null or name = :name) and " +
            " (:gender is null or gender = :gender) ", nativeQuery = true)
    List<TUserEntity> findAllOrgByNameAndGender(@Param("name") String name, @Param("gender") Integer gender);

}
